package com.zhengqing.system.consumer;

import com.alibaba.fastjson.JSONObject;
import com.zhengqing.system.model.dto.ManualCatalogToMailDto;
import com.zhengqing.system.model.dto.YoutubeGetMediaDto;
import com.zhengqing.system.service.IManualModelOmService;
import com.zhengqing.system.service.YoutubeDownloadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName MpConsumer
 * @Description TODO
 * @Author Des1gn
 * @Date 2023/4/11 19:47
 * @Version 1.0
 **/
@Slf4j
@Component
public class MpConsumer {

    @Resource
    IManualModelOmService manualModelOmService;

    @Resource
    YoutubeDownloadService youtubeDownloadService;

    @KafkaListener(topics = {"mp-queue"})
    public void mpConsumer(String message){
        try {
            log.info("kafka consumer mp-> {}",message);
            ManualCatalogToMailDto manualCatalogToMailDto = JSONObject.parseObject(message, ManualCatalogToMailDto.class);
            manualModelOmService.mpGetCatalogToEmailConsumer(manualCatalogToMailDto);
        }catch (Exception e){
            log.error("kafka队列消息处理失败 mp-{}",e);
        }
    }

    @KafkaListener(topics = {"youtube-queue"})
    public void youtubeConsumer(String message){
        try {
            log.info("kafka consumer youtube-> {}",message);
            YoutubeGetMediaDto dto = JSONObject.parseObject(message, YoutubeGetMediaDto.class);
            youtubeDownloadService.downloadProcess(dto);
        }catch (Exception e){
            log.error("kafka队列消息处理失败 youtube-{}",e);
        }
    }

}
